package com.nanhu.sms.broadcast;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.widget.Toast;

public class SmsSendReceiver extends BroadcastReceiver{

	public static String action="com.nanhu.sms.SmsSendReceiver";
	
	@Override
	public void onReceive(Context context, Intent intent) {
		int resultCode = getResultCode();
		if(resultCode == Activity.RESULT_OK){
			Toast.makeText(context, "发送成功！", Toast.LENGTH_SHORT).show();
			
			//存入短信库
			String[] receivers = intent.getStringArrayExtra("receivers");
			String content = intent.getStringExtra("content");
			
			for(String receiver : receivers){
				ContentValues values = new ContentValues();
				values.put("date", System.currentTimeMillis());
				values.put("read", 1);
				values.put("type", 2);
				values.put("address", receiver);
				values.put("body", content);
				context.getContentResolver().insert(Uri.parse("content://sms"), values);
			}
		}else{
			Toast.makeText(context, "发送失败！", Toast.LENGTH_SHORT).show();
		}
	}
	
}
